'''
-*- coding: utf-8 -*-
@File  : 01-v5_det_only.py
@Author: Shanmh
@Time  : 2024/03/19 下午3:51
@Function：
'''

import torch
import cv2


import cv2
import time
from torchsummary import summary
img=cv2.imread("asset/images/person.png")
model = torch.hub.load('./yolov5', 'custom', path="models/yolov5s.pt", source='local',force_reload=True)
# print(model.names)
# print(model.__dict__)
# summary(model)
# # help(model)

size=1
fps=0
last_time=0
while False:
    results = model([img]*size)
    results = eval(results.pandas().xyxy[0].to_json(orient="records"))
    print("##############")
    print(results)
    print("##################")
    for out in results:
        x1, y1, x2, y2 = int(out["xmin"]), int(out["ymin"]), int(out["xmax"]), int(out["ymax"])
        score, c_class, name = out["confidence"], out["class"], out["name"]
        cv2.putText(img, '{}, {:.3f}'.format(name, score),
                    (x1, y1 + 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5,
                    (255, 255, 0), 1)
        cv2.rectangle(img, (x1, y1), (x2, y2), (255, 255, 0), 2)
    fps += size
    if time.time() - last_time > 1:
        print(f"[fps]%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ： {fps}")
        last_time = time.time()
        fps = 0